package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;
import com.chinanet.utils.pon.ZXGetFinalResult;
import com.chinanet.utils.pon.ZX_SocketClient;

import java.util.HashMap;
import java.util.Map;

/**
 * ZX_Query_PON_OLT_under_the_number_of_alarmImp
 * 中兴PON网管-查询OLT PON下的告警数量
 * @author xuzhi
 *
 */
public class ZX_Query_PON_OLT_under_the_number_of_alarmImp implements WorkInterFace {

	public String getName() {
		return "中兴PON网管-查询OLT PON下的告警数量";
	}

	public String getDesciption() {
		return "";
	}

	public int getVersion() {
		return 0;
	}

	public Attr[] getInAttrs() {
		Attr[] in = new Attr[3];
//		in[0] = new Attr("Port", "端口号", AttrType.TYPE_String, true);
		in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
		in[1] = new Attr("BEGINTIME", "开始时间,格式：yyyy-MM-dd HH-mm-ss", AttrType.TYPE_Date, true);
		in[2] = new Attr("PONID", "PON的ID，如：查询OLT设备上0框4槽1端口的光模块信息，PONID为NA-0-4-1", AttrType.TYPE_String, true);
//		in[3] = new Attr("ENDTIME", "结束时间，格式：yyyy-MM-dd HH-mm-ss", AttrType.TYPE_Date, false);
		return in;
	}

	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[10];
		out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true); 
		out[1] = new Attr("Alarmfalg", "查询改pon下是否存在pon LOS告警，1：存在；0：不存在", AttrType.TYPE_Int, true);
		out[2] = new Attr("ONULoscount", "PON口ONU电源掉电的告警数量", AttrType.TYPE_Int, false);
		out[3] = new Attr("ONULosTimeflag", "PON口ONU电源掉电时的时间正确度，1：正确；0：不正确", AttrType.TYPE_Int, false);
		out[4] = new Attr("ONUdowncount", "ONU离线数量", AttrType.TYPE_Int, false);
		out[5] = new Attr("ONUdownTimeflag", "ONU离线的时间正确度，1：正确；0：不正确", AttrType.TYPE_Int, false);
		out[6] = new Attr("OLTPONloscount","光模块失效的数量",AttrType.TYPE_Int,true);
		out[7] = new Attr("XOUNLos","检查ONU所在小区是否停电的数量",AttrType.TYPE_Int,true);
		out[8] = new Attr("mainline","检查主干光纤是否连接正常的数量",AttrType.TYPE_Int,true);
		out[9] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	public Map<String, Object> init(Map<String, Object> data) {
		Map<String, Object> inmap = new HashMap<String, Object>();
		Map<String, Object> intomap = new HashMap<String, Object>();
		Map<String, Object> outmap = new HashMap<String, Object>();
		ZXGetFinalResult result = new ZXGetFinalResult();
		String ip ="134.103.235.44";
		int port = 9820;
		ZX_SocketClient hclient = new ZX_SocketClient(ip, port);
		HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
		attrsin.setOLTID((String) data.get("OLTID"));
		attrsin.setPONID((String) data.get("PONID"));

		String BEGINTIME=(String) data.get("BEGINTIME");
//		String ENDTIME=(String) data.get("ENDTIME");
		attrsin.setBEGINTIME(BEGINTIME);
//		attrsin.setENDTIME(ENDTIME);


		inmap = hclient.init(attrsin,
				OperationType.TYPE_Query_PON_OLT_under_the_number_of_alarms);

		try {
			intomap = result.getPatterns_ALARM((String) inmap.get("ownlog"));
//						intomap = result.getPatterns_ALARM(Test.GetForkText("d:\\11.txt"));
		} catch (Exception e) {
			e.printStackTrace();
		}
//		boolean flag=true;
		boolean flag = (Boolean) inmap.get("flag");
		if (flag) {
			outmap.put("flag", 1);
			outmap.put("log", inmap.get("log"));
//			outmap.put("log", Test.GetForkText("d:\\11.txt"));

		} else {
			outmap.put("flag", 0);
			outmap.put("log", inmap.get("log"));
		}

			outmap.putAll(intomap);

		return outmap;
	}

}
